var session_druginfo=sessionStorage.druginfo =="undefined" ? {}:JSON.parse(sessionStorage.druginfo);
if(sessionStorage.drugstyle == 3){
	waitorder();
};
var main = new Vue({
	el: '#main',
	data: {
		ip:localStorage.ip,
		orderStatus:sessionStorage.drugstyle,//订单状态0未领取，1领取，2已送达,3待接单
		information:session_druginfo,
		drugList: session_druginfo.drugList||[],
		getdruglist:[],
	},
	computed:{
		totalMoney:function(){
			var total=0;
			for (var i=0; i<this.drugList.length;i++){
				total += this.drugList[i].drugPrice * this.drugList[i].drugNumber
			}
			return total;
		}
	},
	methods:{
		signreceive:function(){
			yiyaReceive(this.information.orderStatus,this.information.orderId)
		},
		orderReceiving:function(){
			var arrid=[];
			for (var i=0;i<this.getdruglist.length;i++) {
				if(this.getdruglist[i].status == "未领取" && this.getdruglist[i].orderid){
					arrid.push(this.getdruglist[i].id)
				}
			}
			receivingOrder(arrid)
		}
	}
})
//上传图片
var filer="";
function verify(val) {
	var file = document.getElementById("file") ? document.getElementById("file").files[0]:document.getElementById("file2").files[0];
	var imgtype = file.type
	console.log("图片格式:"+imgtype)
	if(imgtype == "image/jpeg" || imgtype == "image/png") {
		var reader = new FileReader();
		reader.onload= function (e) {
			document.getElementById('imgdome') ? document.getElementById('imgdome').setAttribute('src', e.target.result):document.getElementById('imgdome2').setAttribute('src', e.target.result)
			filer=e.target.result;
        };
        reader.readAsDataURL(file);
     }else {
		log_message("请上传jpg或PNG格式的图片")
	}
}
function yiyaReceive(type,orderId){
	if(!filer){
		log_message("记得拍照哦")
		return false;
	}
	console.log(filer)
	lrz(filer,{
		width:512
	})
	.then(function(rst){
		ajaxPost(
			Url.ASSESS_DEUGORDER,
			{
				"orderId":orderId,
				"type":type,
				"file":rst.base64.match(/base64,(\S*)/)[1]
			},
			function(data){
				console.log(data)
				if(data.status==1){
					log_message(data.message)
					setTimeout("window.history.go(-1)",1500)
				}
			}
		)
	})
}
function waitorder(){
	ajaxGet(
		Url.ASSESS_WAITLIST,
		{
			"idCard":session_druginfo.peopleIdCard,
		},
		function(data){
			if(data.status==1){
				var getdruglist=data.response;
				for (var i=0;i<getdruglist.length;i++) {
					getdruglist[i].orderid=false;
					getdruglist[i].unfold=false;
				}
//				main.information=getdruglist[0]||{};
				main.getdruglist=getdruglist||{};
			}
		}
	)
}
//waitorder();
//接单
function receivingOrder(arrid){
	var objarr={}
	objarr.ids=arrid;
	ajaxPostJson(
		Url.ASSESS_SAVEDRUG,
		objarr,
		function(data){
			console.log(data)
			if(data.status==1){
				log_message(data.message)
				setTimeout("window.history.go(-1)",1500)
			}
		}
	)
}
document.getElementById("main").setAttribute("style","display: block;background: #f5f5f5;");